﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using Ini;
using System.Windows.Forms;

namespace Convert1
{
    public partial class settings : Form
    {
        //Konfigurációfájl helye
        IniFile ini = new IniFile(Environment.CurrentDirectory + "\\ffmpegguiConf.ini");
        string path;
        const int ERROR_FILE_NOT_FOUND = 2;

        public settings()
        {
            InitializeComponent();
            try
            {
                using (StreamReader reader = new StreamReader(Environment.CurrentDirectory + "\\ffmpegguiConf.ini", Encoding.Default))
                {
                    while (!reader.EndOfStream)
                    {
                        listBox1.Items.Add(reader.ReadLine());
                    }
                    reader.Close();
                }
            }
            catch (Win32Exception h)
            {
                if (h.NativeErrorCode == ERROR_FILE_NOT_FOUND)
                {
                    MessageBox.Show(Environment.CurrentDirectory + "\\ffmpegguiConf.ini", "A Fájl Nem Található!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            comboBox1.Text = ini.IniReadValue("Settings", "Color");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items[listBox1.SelectedIndex] = textBox1.Text;
        }

        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            textBox1.Text = listBox1.SelectedItem.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (StreamWriter sw = new StreamWriter(Environment.CurrentDirectory + "\\ffmpegguiConf.ini", false, Encoding.Default))

                foreach (var item in listBox1.Items)
                {
                    sw.WriteLine(item.ToString());
                }


            ini.IniWriteValue("Settings", "Color", comboBox1.Text);
            comboBox1.Enabled = false;

            if (comboBox1.Text == "Fekete")
                Theme.ThemeColor = RibbonTheme.Black;
            else if (comboBox1.Text == "Zöld")
                Theme.ThemeColor = RibbonTheme.Green;
            else if (comboBox1.Text == "Lila")
                Theme.ThemeColor = RibbonTheme.Purple;
            else if (comboBox1.Text == "JellyBelly")
                Theme.ThemeColor = RibbonTheme.JellyBelly;
            else if (comboBox1.Text == "Halloween")
                Theme.ThemeColor = RibbonTheme.Halloween;
            else
                Theme.ThemeColor = RibbonTheme.Normal;
            Form1.ActiveForm.Refresh();
            this.Refresh();
            comboBox1.Enabled = true;
            comboBox1.Focus();
            this.Close();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://ffmpeg.zeranoe.com/builds");
        }



    }
}
